import AnyButton from '@/components/AnyButton'
import type { IButtonProps, Optional } from '@/typed/components'
import type { RouteLocationRaw } from 'vue-router'

// 去掉 IButtonProps 中的 to 属性，方便后面重新定义
type TableActionProps = Optional<IButtonProps, 'to'>

export interface TableActionModel extends TableActionProps {
	label?: string
	to?: RouteLocationRaw
	key?: string
	hidden?: boolean //  根据条件是否隐藏
	dir?: {
		[key: string]: string[]
	}
}

export const useRenderAction = function (actions: TableActionModel[] | any[]) {
	return actions
	.filter((i) => i && !i.hidden)
	.map((it) => {
		const {label, ...other} = it
		return (
			<AnyButton
				type={'primary'}
				size={'small'}
				{...other}
			>
				{label}
			</AnyButton>
		)
	})
}
